#include "Particles.h"
#include "Emitter.h"


// overloaded ctor (attach to current emitter and set variables)
Particles::Particles(Emitter* import)
{
	// attach emmit to current emitter
	emmit = import;

	// FLOATs
	maxAge = import->GetMaxParticleAge();
	startRotation = import->GetStartRotation();
	currRotation = import->GetStartRotation();
	endRotation = import->GetEndRotation();

	// VECTOR2s
	position = import->GetPosition();
	startVelocity = import->GetStartVelocity();
	currVelocity = import->GetStartVelocity();
	endVelocity = import->GetEndVelocity();
	startScale = import->GetStartScale();
	currScale = import->GetStartScale();
	endScale = import->GetEndScale();

	// COLORs
	startColor = import->GetStartColor();
	currColor = import->GetStartColor();
	endColor = import->GetEndColor();
}

void Particles::Update(float elapsedTime)
{
	// color blending - Lerp each color variable (ARGB)
	currA = startColor.alpha + (endColor.alpha - startColor.alpha) * (currAge / maxAge);
	currR = startColor.red + (endColor.red - startColor.red) * (currAge / maxAge);
	currG = startColor.green + (endColor.green - startColor.green) * (currAge / maxAge);
	currB = startColor.blue + (endColor.blue - startColor.blue) * (currAge / maxAge);
	// set new color
	currColor = SGD::Color((int)currA, (int)currR, (int)currG, (int)currB);

	// scale blending
	currScale = startScale + (endScale - startScale) * (currAge / maxAge);

	// rotation blending
	currRotation += (startRotation + (endRotation - startRotation) * (currAge / maxAge)) *elapsedTime;

	// velocity blending
	currVelocity = startVelocity + (endVelocity - startVelocity) * (currAge / maxAge);

	// update particle position
	position += (currVelocity * elapsedTime);
	// update particle age
	currAge += elapsedTime;
}
